<?php
/**
 * @copyright © 2015 Huxun. All Rights Reserved
 * @author silm 
 * @see 用户操作业务类 
 * @version 0.0.1
 * 
 */
class UserEntity extends MysqlPDO {
	/**
	 *
	 * @see 构造函数
	 */
	function __construct() {
		parent::__construct ( 'user', array (
				'id',
				'account',
				'password',
				'company_name',
				'principal', // 责任人
				'phone',
				'deleted',
				'register_time' 
		) );
	}
	
	/**
	 *
	 * @see mysql_manager::__destruct()
	 */
	function __destruct() {
		parent::__destruct ();
	}
	
	/**
	 *
	 * @see 通过用手机号获取用户信息
	 * @param int $name        	
	 * @return false|array 成功返回用户信息，失败返回false
	 *        
	 */
	function get_by_phone($phone) {
		if (empty ( $phone ))
			return false;
		$where = array (
				'phone' => $phone,
				'deleted' => '0' 
		);
		$ret = parent::get_records ( $where, 1, 1 );
		if (false == $ret)
			return false;
		return $ret [0];
	}
	/**
	 *
	 * @see 通过用户帐号获取用户信息
	 * @param int $account        	
	 * @return false|array成功返回用户信息，失败返回false
	 */
	function get_by_account($account) {
		if (empty ( $account ))
			return false;
		$where = array (
				'account' => $account,
				'deleted' => '0' 
		);
		$ret = parent::get_records ( $where, 1, 1 );
		if (false === $ret)
			return false;
		return $ret [0];
	}
	/**
	 *
	 * @see 获取用户信息
	 * @param unknown $id        	
	 * @return multitype:
	 */
	function get($id) {
		if (empty ( $id ))
			return false;
		$where = array (
				'id' => $id,
				'deleted' => 0 
		);
		$ret = parent::get_records ( $where, 1, 1 );
		if (false == $ret)
			return false;
		return $ret [0];
	}
	/**
	 *
	 * @param int $page        	
	 * @param number $count        	
	 * @param array $where        	
	 * @param array $order        	
	 * @return false|array
	 */
	function get_list($page, $count = 10, $where, $order) {
		return parent::get_records ( $where, $page, $count, null, $order );
	}
	
	/**
	 *
	 * @see 通过用户名伪删除用户信息
	 * @param string $uname        	
	 * @return boolean
	 */
	function delete_bugos($id) {
		if (empty ( $id ))
			return false;
		return parent::delete_records_bogus ( array (
				'id' => $id 
		) );
	}
	
	/**
	 *
	 * @see 验证登录
	 * @param string $name        	
	 * @param string $pwd        	
	 * @return boolean|id
	 */
	function check_login($name, $pwd) {
		if (empty ( $name ) || empty ( $pwd ))
			return false;
		$sql = "select id from user where account='$name' and password = '$pwd' and deleted=0";
		fb ( $sql );
		$ret = parent::query ( $sql );
		if (false === $ret || count ( $ret ) === 0)
			return false;
		return $ret [0] ['id'];
	}
}